﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
// add
using FormBaseLib;
using FormBase;

namespace FormBase
{
    public partial class FPGM0110 : Form 
    {
        CBase mLastError = new CBase();
        CSerializationSample mSerialization1 = new CSerializationSample();
        string msFile = "FPGM0110.txt";
        public FPGM0110()
        {
            InitializeComponent();
        }

        private void FPGM0110_Load(object sender, EventArgs e)
        {
            mSerialization1.Age = 100;
            mSerialization1.Male = false;
            mSerialization1.name = "Susand";
        }

        private void saveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //CSerializationSample serial1 = new CSerializationSample();

            mSerialization1.SetDefault();
            txtMultiline2.Clear();
            if (mSerialization1.SerializerToFile(msFile))
                txtMultiline2.Text = mSerialization1.Dump();
            else
                CProject.mApp.PopupError("Can't save to " + msFile);

// save sample:
//<?xml version="1.0"?>
//<CSerializationSample xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" 

//name="Susand">
//  <Age>100</Age>
//  <Male>false</Male>
//</CSerializationSample>onSample>
            //MessageBox.Show("OK");
        }

        private void loadToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //CSerializationSample so1 = new CSerializationSample();
            //so1 = so1.Load(msFile);
            txtMultiline1.Clear();
            if (mSerialization1.DescrializeFromFile(msFile))
                txtMultiline1.Text = mSerialization1.Dump();
            else
                CProject.mApp.PopupError("Can't load from " + msFile);
        }

        private void setKeyToolStripMenuItem_Click(object sender, EventArgs e)
        {
            CSerializationSample so1 = new CSerializationSample();
            CSerializationSample so2 = new CSerializationSample();
            so1.DescrializeFromFile(msFile);
            so2 = CCommon.CopyDeepFromSerializable(so1);
            txtMultiline1.Text = so1.Dump();
            txtMultiline2.Text = CCommon.DumpSerializableToXML(so2);
        }

        private void menuLoadError_Click(object sender, EventArgs e)
        {

            //if (mSerialization1.DeserializeFromFileUTF8(msFile))
            if (mSerialization1.DescrializeFromFile(msFile))
                txtMultiline1.Text = mSerialization1.Dump();
            else
                CProject.mApp.PopupError("Can't load from " + msFile);

        }

        private void menuSaveError_Click(object sender, EventArgs e)
        {
            txtMultiline2.Clear();
            //if (mSerialization1.SerializeToFileUTF8(msFile))
            if (mSerialization1.SerializerToFile(msFile))
                txtMultiline2.Text = mSerialization1.Dump();
            else
                CProject.mApp.PopupError("Can't save to " + msFile);

        }
    }
}
